#include <iostream>

using namespace std;
template <typename T, int size> 

class SeqList {
  public:
    SeqList();
    void addData(const T &data) {
      if (index >= size) {
        cout << "list is full" << endl; 
      } else {
        buf[index] = data;
        index++;
      }
    }
    void show(void) const;
    ~SeqList() {
      if (buf) {
        delete [] buf;
      }
    }
  private:
    T * buf;
    int index;  
};

// 成员函数在类外定义的形式
template <typename T, int size> SeqList<T, size>::SeqList() {
  if (size == 0) {
    cout << "size can't be zero" << endl;
  }
  buf = new T[size];
  this->index = 0;
}
// show
template <typename T, int size> void SeqList<T, size>::show(void) const {
  for (int i = 0; i < index; i++) {
    cout << buf[i] << " ";
  }
  cout << endl;
}

int main(int argc, char const *argv[])
{
  /* code */ //栈中分配， 由os进行内存的分配和管理
  SeqList<int, 10> seq;
  seq.addData(1);
  seq.addData(35);
  seq.show();
  return 0;
}
